<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>用户机构</title>
	<link rel="stylesheet" th:href="@{/static/layui/css/layui.css}" media="all"/>
	<link rel="stylesheet" th:href="@{/static/css/footer.css}" media="all"/>
	<link rel="stylesheet" th:href="@{/static/css/thesame.css}" media="all"/>
	<link rel="stylesheet" th:href="@{/static/css/tree.css}" media="all"/>
	<link rel="stylesheet" th:href="@{/static/css/popCss.css}" media="all"/>
	<link rel="stylesheet" th:href="@{/static/mealUser/css/user.css}"  media="all"/>
	<style type="text/css">
        /*取消选中效果*/
		div{
	    -moz-user-select:none;/*火狐*/
	    -webkit-user-select:none;/*webkit浏览器*/
	    -ms-user-select:none;/*IE10*/
	    -khtml-user-select:none;/*早期浏览器*/
	      user-select:none;
		}
		.layui-form-checkbox[lay-skin="primary"]{padding-left: 0px;}
		.add-mess-child .tree-con-box .tree-one{height: 240px;}
    </style>
</head>
<script th:inline="javascript">var basePath = [[${#httpServletRequest.getContextPath()}]];</script>
<body>
<div class="add-title pad25px"><span onclick="returnUserList()" style="cursor: pointer;"  class="mr10px"><img th:src="@{/static/img/return_icon.png}"></span><span id="actionTitle">查询机构</span></div>
<div class="new-add-box new-add-box-width bgWhite box-shadows border-radius4">
	<div class="new-add-box-scroll">
		<div class="add-mess add-mess-mb mar25px">
			<article class="overflow">
				<div class="add-mess-child">
					<div>
						<label>供餐机构：</label>
					</div>
					<div class="add-mess-form" id="mealName"></div>
				</div>
				<div class="add-mess-child">
					<div>
						<label>登录账号：</label>
					</div>
					<div class="add-mess-form" id="loginName"></div>
				</div>
				<div class="add-mess-child">
					<div>
						<label>用户名：</label>
					</div>
					<div class="add-mess-form" id="userName"></div>
				</div>
				<div class="add-mess-child">
					<div>
						<label>手机号码：</label>
					</div>
					<div class="add-mess-form" id="phone"></div>
				</div>
			</article>
			<div id="treeThree" class="add-mess-child add-mess-child-gray">
				<div>
					<label>供餐区域：</label>
				</div>
				<div>
					<div class="tree-con-box layui-form border1px" style="height: 240px; margin-top: 10px;top: 0; left: 80px; width: 400px; box-shadow: none;">
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
</div>
<div class="layui-footer layui-footer-one">
	<div class="btn-con textCenter">
		<span id="returnBtn" style="cursor: pointer;width:110px;" onclick="returnUserList()" class="btn-one">返回列表</span>
		<span id="deleteBtn" style="cursor: pointer;" th:attr="data-no=${userNo}"  onclick="deleteUser(this)" class="btn-two">删&nbsp;除</span>
		<span id="editBtn" style="cursor: pointer;" th:attr="data-no=${userNo}" onclick="editUser(this)" class="btn-two">编&nbsp;辑</span>
	</div>
</div>
</body>
<script type="text/javascript" th:src="@{/static/js/jquery-2.1.3.min.js}" charset="utf-8"></script>
<script type="text/javascript" th:src="@{/static/js/layuiCon.js}" charset="utf-8"></script>
<script type="text/javascript" th:src="@{/static/layui/layui.js}" charset="utf-8"></script>
<script type="text/javascript" th:src="@{/static/js/date.js}" charset="utf-8"></script>
<script type="text/javascript" th:src="@{/static/js/treeTwo.js}" charset="utf-8"></script>
<script type="text/javascript" th:src="@{/static/js/treeThree.js}" charset="utf-8"></script>

<script>

	//layer初始化
	var layer;
	layui.use('layer', function(){
		layer = layui.layer;
	});

	$(function(){
		$('.add-person ul li').click(function(){
			$(this).addClass('cur-green').siblings().removeClass('cur-green');
		})
		//授权机构树初始化
		authOrgInit();
		//查询初始化
		queryUserInit();
	})

	/**
	 * 返回列表
	 */
	function returnUserList(){
		window.location.href=basePath+"/mealUser/listPage";
	}

	/**
	 * 授权机构树初始化
	 */
	function authOrgInit(){
		var userNo = '[[${userNo}]]';
		$.ajax({
			type: "post",
			url: basePath + "/org/getAllAuthOrg",
			dataType: "json",
			data: {"userNo": userNo},
			success: function (data) {
				var str = "";
				$.each(data.children, function (index, ao) {
					if (ao.isChildExist == '1' && data.children.length > 0) {
						str += '<ul class="tree-one">';
						$.each(ao.children, function (index, ao1) {
							str += '<li>';
							str += '<div class="tree-children">';
							str += '<div>';
							str += '<p class="mr5px"><input lay-filter="switchTest" type="checkbox" '+(ao1.authType == 0?' ':checked="checked")+' data-state="0" data-parentorgid="' + ao1.parentOrgId + '" id="' + ao1.orgId + '" name="" lay-skin="primary"></p>';
							str += ao1.isChildExist == '1'?'<p class="tree-arrow cursor"><img src="'+ basePath +'/static/user/img/icon_select_down.png"></p><p>' + ao1.orgName + '</p>':'<p style="margin-left: 8px;margin-right: 6px;">' + ao1.orgName + '</p>';
							str += '</div>';
							str += '</div>';
							if (ao1.isChildExist == '1' && ao.children.length > 0) {
								str += '<ul class="tree-two">';
								$.each(ao1.children, function (index, ao2) {
									str += '<li>';
									str += '<div class="tree-children">';
									str += '<div>';
									str += '<p class="mr5px"><input lay-filter="switchTest" type="checkbox" '+(ao2.authType == 0?' ':checked="checked")+' data-state="0" data-parentorgid="' + ao2.parentOrgId + '" id="' + ao2.orgId + '" name="" lay-skin="primary"></p>';
									str += ao2.isChildExist == '1'?'<p class="tree-arrow cursor"><img src="'+ basePath +'/static/user/img/icon_select_down.png"></p><p>' + ao2.orgName + '</p>':'<p style="margin-left: 8px;margin-right: 6px;">' + ao2.orgName + '</p>';
									str += '</div>'
									str += '</div>';
									if (ao2.isChildExist == '1' && ao1.children.length > 0) {
										str += '<ul class="tree-three">';
										$.each(ao2.children, function (index, ao3) {
											str += '<li>';
											str += '<div class="tree-children">';
											str += '<div>';
											str += '<p class="mr5px"><input lay-filter="switchTest" type="checkbox" '+(ao3.authType == 0?' ':checked="checked")+' data-state="0" data-parentorgid="' + ao3.parentOrgId + '" id="' + ao3.orgId + '" name="" lay-skin="primary"></p>';
											str += ao3.isChildExist == '1'?'<p class="tree-arrow cursor"><img src="'+ basePath +'/static/user/img/icon_select_down.png"></p><p>' + ao3.orgName + '</p>':'<p style="margin-left: 8px;margin-right: 6px;">' + ao3.orgName + '</p>';
											str += '</div>';
											str += '</div>';
											if (ao3.isChildExist == '1' && ao2.children.length > 0) {
												str += '<ul class="tree-four">';
												$.each(ao3.children, function (index, ao4) {
													str += '<li>';
													str += '<div class="tree-children">';
													str += '<div>';
													str += '<p class="mr5px"><input lay-filter="switchTest" type="checkbox" '+(ao4.authType == 0?' ':checked="checked")+' data-state="0" data-parentorgid="' + ao4.parentOrgId + '" id="' + ao4.orgId + '" name="" lay-skin="primary"></p>';
													str += ao4.isChildExist == '1'?'<p class="tree-arrow cursor"><img src="'+ basePath +'/static/user/img/icon_select_down.png"></p><p>' + ao4.orgName + '</p>':'<p style="margin-left: 8px;margin-right: 6px;">' + ao4.orgName + '</p>';
													str += '</div>';
													str += '</div>';
													if (ao4.isChildExist == '1' && ao3.children.length > 0) {
														str += '<ul class="tree-five">';
														$.each(ao4.children, function (index, ao5) {
															str += '<li>';
															str += '<div class="tree-children">';
															str += '<div>';
															str += '<p class="mr5px"><input lay-filter="switchTest" type="checkbox" '+(ao5.authType == 0?' ':checked="checked")+' data-state="0" data-parentorgid="' + ao5.parentOrgId + '" id="' + ao5.orgId + '" name="" lay-skin="primary"></p>';
															str += ao5.isChildExist == '1'?'<p class="tree-arrow cursor"><img src="'+ basePath +'/static/user/img/icon_select_down.png"></p><p>' + ao5.orgName + '</p>':'<p style="margin-left: 8px;margin-right: 6px;">' + ao5.orgName + '</p>';
															str += '</div>';
															str += '</div>';
															str += '</li>';
														})
														str += '</ul>';
													}
													str += '</li>';
												})
												str += '</ul>'
											}
											str += '</li>';
										})
										str += '</ul>';
									}
									str += '</li>';
								})
								str += '</ul>';
							}
							str += '</li>';
						});
						str += '</ul>';
					}
					str += '';
					$("#treeThree .tree-con-box").html(str);
					//授权机构树点击功能初始化
					treeThreeInit();
					//机构数全部展开
					$('#treeThree ul').show();
					//禁止点击
					$('input').attr("disabled","disabled");
				});
			}
		})
	}

	/**
	 * 判断是否为空
	 */
	function isNull(value) {
		return value == null || value === "" || value === undefined;
	}

	/**
	 * layer msg
	 */
	function layerMsg(msg){
		var layer;
		layui.use(['layer'], function() {
			layer = layui.layer;
			layer.ready(function(){
				layer.msg(msg);
			});
		});
	}

	/**
	 * layer result
	 */
	function layerResult(msg,type){
		var layer;
		layui.use(['layer'], function() {
			layer = layui.layer;
			layer.ready(function(){
				layer.msg(msg, {icon: type, time:1500});
			})
		});
	}

	/**
	 * layer checkbox
	 */
	function checkBoxInit(){
		layui.use(['form'], function() {
			var form = layui.form;
			form.render('checkbox');
		});
	}

	/**
	 * 查询初始化
	 */
	function queryUserInit(){
		var userNo = '[[${userNo}]]';
		if(!isNull(userNo)){
			$.ajax({
				type:"post",
				url:basePath+"/mealUser/getUserById",
				dataType:"json",
				data:{"userNo":userNo},
				success:function(rst){
					$("#userNo").html(rst.data.USER_NO);
					$("#mealName").html(rst.data.MEAL_NAME);
					$("#loginName").html(rst.data.LOGIN_NAME);
					$("#userName").html(rst.data.USER_NAME);
					$("#phone").html(rst.data.PHONE);
					var loginTime = rst.data.LOGIN_TIME;
					if(loginTime!=null){
						$("#deleteBtn").hide();
					}
				}
			})
		}
	}

	/**
	 * 用户删除
	 */
	function deleteUser(obj){
		var no = $(obj).data("no");
		var args=[];
		args.push(no);
		deleteCon("",deleteUserCommit, args, 1);
	}

	/**
	 * 用户删除提交
	 */
	function deleteUserCommit(id) {
		$.ajax({
			url:basePath+"/mealUser/delete",
			type:"post",
			dataType:"json",
			data:{"userNo":id,"postType":"2"},
			success:function (result) {
				if(result.code == 200){
					layerResult("删除成功",1);
				}else{
					layerResult("删除失败",2);
				}
			}
		})
	}

	/**
	 * layer result
	 */
	function layerResult(msg,type){
		var layer;
		layui.use(['layer'], function() {
			layer = layui.layer;
			layer.ready(function(){
				layer.msg(msg, {icon: type, time:1500},function(){
					window.location.href=basePath+"/mealUser/listPage";
				});
			})
		});
	}

	/**
	 * 跳转到修改用户
	 */
	function editUser(obj){
		var no = $(obj).data("no");
		window.location.href=basePath+"/mealUser/editPage?userNo="+no;
	}


</script>
</body>
</html>
